﻿@{
    ViewBag.Title = "明细账明细";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<style type="text/css">
    ul, li {
        list-style: none;
    }

    div, ul, li, header {
        padding: 0;
        margin: 0;
    }

    .clear {
        clear: both;
    }

    #wrapper {
    }



        #wrapper header {
            height: 3em;
            line-height: 2em;
            padding: 0.5em;
            border-bottom: 1px solid #ccc;
        }

            #wrapper header div.f_r {
                float: right;
                height: 2em;
            }

            #wrapper header .butn_common {
                float: left;
                height: 2em;
                padding: 0 1em 0 2em;
                background-color: #1ABC9C;
                display: inline-block;
                border: none;
                border-right: 1px solid #ccc;
                color: #fff;
                position: relative;
            }

                #wrapper header .butn_common span {
                    position: absolute;
                    left: 0.5em;
                    top: 0.5em;
                    width: 1em;
                    height: 1em;
                }

                #wrapper header .butn_common:first-child {
                    border-top-left-radius: 0.5em;
                    border-bottom-left-radius: 0.5em;
                }

                #wrapper header .butn_common:last-child {
                    border-top-right-radius: 0.5em;
                    border-bottom-right-radius: 0.5em;
                    border-right: none;
                }




            #wrapper header .f_l {
                float: left;
                height: 2em;
            }

                #wrapper header .f_l .input_area {
                    float: left;
                    height: 2em;
                    position: relative;
                    padding: 0 0 0 5.5em;
                }

                    #wrapper header .f_l .input_area .input_title {
                        height: 2em;
                        position: absolute;
                        width: 5em;
                        top: 0;
                        left: 0;
                        text-align: right;
                        font-size: 1em;
                        padding: 0;
                        margin: 0;
                        line-height: 2em;
                    }

                    #wrapper header .f_l .input_area .input_c {
                        height: 2em;
                        border: 1px solid #ccc;
                        box-sizing: border-box;
                        background-color: #fff;
                    }


                #wrapper header .f_l .input_c_w12 {
                    width: 15em;
                }

                #wrapper header .f_l .input_c_w15 {
                    width: 25em;
                }


                #wrapper header .f_l .input_c_w20 {
                    width: 24em;
                }

                #wrapper header .f_l .input_area .input_c input.txt_common {
                    height: 100%;
                    width: 100%;
                    border: none;
                    background-color: transparent;
                }

                #wrapper header .f_l .input_area .input_c select.sel_common {
                    height: 100%;
                    width: 100%;
                    border: none;
                    background-color: transparent;
                }

        #wrapper .c_container {
            padding: 1em;
        }

            #wrapper .c_container .tabs {
                line-height: 2em;
                padding: 0 0.5em;
                border-bottom: 1px solid #1ABC9C;
            }

                #wrapper .c_container .tabs .tab {
                    height: 2em;
                    float: left;
                    padding: 0 1em;
                    margin: 0 0 0 0.1em;
                    background-color: #fff;
                    cursor: pointer;
                    border-top-left-radius: 0.5em;
                    border-top-right-radius: 0.5em;
                    border-left: 1px solid #ccc;
                    border-right: 1px solid #ccc;
                    border-top: 1px solid #ccc;
                }

                #wrapper .c_container .tabs .tab_cur {
                    background-color: #1ABC9C;
                    color: #fff;
                }

            #wrapper .c_container .tab_contentc {
                border-left: 1px solid #1ABC9C;
                border-right: 1px solid #1ABC9C;
                border-bottom: 1px solid #1ABC9C;
                height: 64em;
                overflow: hidden;
            }

                #wrapper .c_container .tab_contentc .tab_contents {
                    width: 200%;
                    height: 64em;
                }

                    #wrapper .c_container .tab_contentc .tab_contents .tab_content {
                        width: 50%;
                        height: 64em;
                        overflow: auto;
                        float: left;
                    }

        #wrapper div.table_c {
            border-left: 1px solid #ccc;
            border-right: 1px solid #ccc;
            height: 59em;
            border-collapse: collapse;
            overflow: hidden;
            overflow-y: auto;
        }

            #wrapper div.table_c table {
                line-height: 3em;
                box-sizing: border-box;
                width: 100%;
                border-collapse: collapse;
                border-bottom: 1px solid #ccc;
            }

                #wrapper div.table_c table tr th {
                    border-bottom: 1px solid #ccc;
                    border-right: 1px solid #ccc;
                    height: 3em;
                    font-weight: normal;
                    text-align: center;
                    background-color: #eee;
                }

                    #wrapper div.table_c table tr th:last-child {
                        border-right: none;
                    }

                #wrapper div.table_c table tr td {
                    border-bottom: 1px solid #ccc;
                    border-right: 1px solid #ccc;
                    height: 3em;
                    text-align: center;
                    padding: 0 0.5em;
                    box-sizing: border-box;
                }

                #wrapper div.table_c table tr:hover td {
                    background-color: #eee;
                }

                #wrapper div.table_c table tr.selected td {
                    background-color: #35a4c9;
                }

                #wrapper div.table_c table tr:last-child td {
                    border-bottom: none;
                }

                #wrapper div.table_c table tr td:last-child {
                    border-right: none;
                }

                #wrapper div.table_c table tr td:nth-child(2), #wrapper div.table_c table tr td:nth-child(3), #wrapper div.table_c table tr td:nth-child(5), #wrapper div.table_c table tr td:nth-child(6) {
                    text-align: left;
                }

                #wrapper div.table_c table tr td:nth-child(1) {
                    width: 4em;
                }

                #wrapper div.table_c table tr td:nth-child(2) {
                    width: 10em;
                }

                #wrapper div.table_c table tr td:nth-child(3), #wrapper div.table_c table tr td:nth-child(5) {
                    width: 28em;
                }

                #wrapper div.table_c table tr td:nth-child(4) {
                    width: 18em;
                }

                #wrapper div.table_c table tr td:nth-child(6) {
                    width: 10em;
                }

        #wrapper div.page_view {
            height: 3em;
            border: 1px solid #ccc;
            padding: 0 1em;
        }

            #wrapper div.page_view div.page_total {
                height: 3em;
                line-height: 3em;
                float: right;
            }

            #wrapper div.page_view div.pages {
                height: 2em;
                padding: 0.5em 0;
            }

            #wrapper div.page_view a.page:link, #wrapper div.page_view a.page:visited {
                height: 2em;
                width: 2em;
                display: inline-block;
                float: left;
                margin: 0 0.5em 0 0;
                text-indent: -9999px;
            }

            #wrapper div.page_view a.page:hover {
                height: 2em;
                width: 2em;
                display: inline-block;
                float: left;
                margin: 0 0.5em 0 0;
                background-color: #eee;
            }

            #wrapper div.page_view input.txt_page, #wrapper div.page_view select.show_page {
                float: left;
                height: 2em;
                width: 4em;
                border: 1px solid #ccc;
                box-sizing: border-box;
                text-align: center;
                margin: 0 0.5em 0 0;
            }

            #wrapper div.page_view div.pages div.show_page {
                float: left;
                height: 2em;
                margin: 0 0.5em 0 0;
                line-height: 2em;
            }

    ._bg_bg_page_01 {
        background-size: cover;
        background-image: url();
    }

    ._bg_bg_page_02 {
        background-size: cover;
        background-image: url();
    }

    ._bg_bg_page_03 {
        background-size: cover;
        background-image: url();
    }

    ._bg_bg_page_04 {
        background-size: cover;
        background-image: url();
    }
</style>

<script type="text/javascript">
    $(function () {
        Index.init();


    });
    
    var Index = {
        productUnits:@Html.Raw(ViewData["productUnitList"].ToString()),
        sparePartsLists:@Html.Raw(ViewData["sparePartsList"].ToString()),
        defaultDate:@Html.Raw(ViewData["LedgerDate"].ToString()),
        UseUnit:'25000',
        init: function () {
            with (Index) {
                initTable();
                
                initControl();
                
                initDicData();

                $("#butnQuery").trigger("click");
            }
        },
        initTable: function () {
            $(".table_c table").delegate("td", "click", function () {
                $(this).parents("tr").addClass("selected");

                $(this).parents("tr").siblings().removeClass("selected");
            });

            $(".table_c table").delegate("td", "dblclick", function () {
                $("#butnDetails").trigger("click");
            });
        },
        initControl: function () {
            $("#txtDate").val(new Date().format("yyyyMM"));

            $("[date-control]").on("click", function () {
                WdatePicker({ dateFmt: 'yyyyMM', minDate: '2000-1', maxDate: '2050-12' });
            });
            
            $("#butnDetails").on("click", function () {
                var jsonData = {param:$(".table_c table tr.selected").attr("rowData")};
                
                var url = "/WareHouse/EnterWareHouse/WareHouseLedgerDetails?{0}".format($.param(jsonData));

                location.href = url;
            });
            
            $("#butnQuery").on("click", function () {
                with(Index){
                    loadData(function(data){
                        var exclude = "UseUnit,FAccountDate,FProductionTypeNO,Fprice_X,FSafetystore,FLowestStore,FHighestStore".split(",");
                    
                        renderData($("#dataList"),data,exclude);
                    });
                }
            });
            
            $("#butnExportExcel").on("click",function(){
                var colNames = "pu,sp,no,name,date".split(",");

                var parames = {},con="";

                colNames.forEach(function(cur){
                    parames[cur] = $("[name={0}]".format(cur)).val();
                });
                
                parames["isCurrent"] = (Index.defaultDate ==$("[name=date]").val()?"1":"0");

                var param = {sql:""};

                param.sql = sql = " SELECT DISTINCT UseUnit,FAccountDate,FProductionNO AS 零件编号,FProductionName AS 零件名称,FProCompanyNO AS 制造单位,FProCompanyName AS 制造单位名称,FProductionTypeNO ,FProductionTypeName as 零件分类,Fprice_X,FSafetystore,FLowestStore,FHighestStore FROM dbo.V_CPK_44_MX_StoCPKListAcco_Mid_MXZMX WHERE UseUnit = '{1}' AND FAccountDate = '{0}'  {2} order by FProductionNO,FProCompanyNO";
                
                "0"==parames["isCurrent"] &&  (sql = "SELECT DISTINCT UseUnit,FAccountDate,FProductionNO AS 零件编号,FProductionName  AS 零件名称,FProCompanyNO AS 制造单位,FProCompanyName AS 制造单位名称,FProductionTypeNO,FProductionTypeName as 零件分类,Fprice_X,FSafetystore,FLowestStore,FHighestStore  FROM V_CPK_47_MX_StoCPKListAcco_Arc_MXZMX  WHERE UseUnit =' {1} ' AND FAccountDate ='{0}' {2}  order  by FProductionNO,FProCompanyNO");
                
                ""!=parames["pu"] && (con+=" and FProCompanyNO = '{0}' ".format(parames["pu"]));

                ""!=parames["sp"] && (con+=" and FProductionTypeNO = '{0}' ".format(parames["sp"]));

                ""!=parames["no"] && (con+=" and FProductionNO = '{0}' ".format(parames["no"]));

                ""!=parames["name"] && (con+="  and FProductionName like '%{0}%'  ".format(parames["name"]));
                
                param.sql = param.sql.format(parames["date"], Index.UseUnit, con);

                var url = "/Common/ExcelExport?{0}".format($.param(param));

                location.href=url;
            });
        },
        initDicData:function(){
            var pu = $("#selProductUnitList"),sp=$("#selSparePartsLists");

            Index.sparePartsLists.forEach(function(cur){
                $("<option value=\"{FTypeNO}\">{FTypeNO} {FTypeName}</option>".format(cur)).appendTo(sp);
            });

            Index.productUnits.forEach(function(cur){
                $("<option value=\"{UnitNO}\">{UnitNO} {UnitShortName}</option>".format(cur)).appendTo(pu);
            });
        },
        loadData:function(onLoadComplate){
            var colNames = "pu,sp,no,name,date".split(",");

            var param = {};

            colNames.forEach(function(cur){
                param[cur] = $("[name={0}]".format(cur)).val();
            });
            
            param["isCurrent"] = (Index.defaultDate ==$("[name=date]").val()?"1":"0");

            $.post("/WareHouse/EnterWareHouse/GetLedgers",{param:JSON.stringify(param)},function(res){
                !!res.status && (function(msg){
                    alert(msg);
                })(res.err_msg);
                
                !res.status &&(function(){
                    onLoadComplate && onLoadComplate(res.content);
                })(); 
            },"json");
        },
        renderData:function(c,data,hiddenCols){
            c.empty();

            var colunms = [];
            
            data.forEach(function(cur){
                !colunms.length && (function(){
                    var title = $("<tr>");

                    for(var idx in cur){
                        0 <= hiddenCols.indexOf(idx) || (function(){
                            colunms.push(idx);
                            
                            $("<th>").text(idx).appendTo(title);
                        })();
                    }

                    title.appendTo(c);
                })();

                !!colunms.length && (function(){
                    var row = $("<tr>");

                    row.attr("rowData",JSON.stringify(cur));

                    //hiddenCols.forEach(function(hiddenCol){
                    //    !cur[hiddenCol] &&(cur[hiddenCol]="");

                    //    row.attr(hiddenCol,cur[hiddenCol]);
                    //});

                    for(var idx in colunms){
                        $("<td>").text(cur[colunms[idx]]).appendTo(row);
                    }

                    row.appendTo(c);
                })();
            });
        }
    };

</script>
<body>
    <div id="wrapper">
        <header>
            <div class="f_r">
                <button id="butnDetails" class="butn_common">
                    <span class="glyphicon glyphicon-refresh"></span>明细
                </button>
                <button id="butnQuery" class="butn_common">
                    <span class="glyphicon glyphicon-refresh"></span>查询
                </button>
                <button class="butn_common">
                    <span class="glyphicon glyphicon-refresh"></span>结账
                </button>
                <button class="butn_common">
                    <span class="glyphicon glyphicon-trash"></span>打印
                </button>
                <button id="butnExportExcel" class="butn_common">
                    <span class="glyphicon glyphicon-download"></span>导出
                </button>
            </div>
            <div class="f_l">
                <div class="input_area input_c_w15">
                    <h2 class="input_title">零件编号</h2>
                    <div class="input_c">
                        <input id="txtLedgerNo" name="no" type="text" class="txt_common" />
                    </div>
                </div>
                <div class="input_area input_c_w20">
                    <h2 class="input_title">零件名称</h2>
                    <div class="input_c">
                        <input id="txtLedgerName" name="name" type="text" class="txt_common" />
                    </div>
                </div>
                <div class="input_area input_c_w15">
                    <h2 class="input_title">制造单位</h2>
                    <div class="input_c">
                        <select id="selProductUnitList" name="pu" class="sel_common ">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="input_area input_c_w12">
                    <h2 class="input_title">零件分类</h2>
                    <div class="input_c">
                        <select id="selSparePartsLists" name="sp" class="sel_common">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="input_area input_c_w12">
                    <h2 class="input_title">台账日期</h2>
                    <div class="input_c">
                        <input id="txtDate" name="date" type="text" class="txt_common" date-control placeholder="请选择" />
                    </div>
                </div>
            </div>
        </header>
        <div class="table_c">
            <table id="dataList">
                <tr><td>正在加载数据。。。</td></tr>
                <!--<tr>
                    <th>序号
                    </th>
                    <th>零件编号
                    </th>
                    <th>零件名称
                    </th>
                    <th>制造单位
                    </th>
                    <th>制造单位名称
                    </th>
                    <th>零件分类
                    </th>
                    <th>备注
                    </th>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>1	
                    </td>
                    <td>9435068580	
                    </td>
                    <td>TX3左后纵梁总成		
                    </td>
                    <td>M105830000	
                    </td>
                    <td>东风（武汉）汽车零部	
                    </td>
                    <td>GV
                    </td>
                    <td></td>
                </tr>-->
            </table>
        </div>
        <div class="page_view">
            <div class="page_total">显示第 1 - 1 条记录　检索到 1 条记录</div>
            <div class="pages">
                <a href="javascript:void(0);" class="page _bg_bg_page_01">首页</a>
                <a href="javascript:void(0);" class="page _bg_bg_page_02">上页</a>
                <input type="text" class="txt_page" value="1" />
                <div class="show_page">共一页</div>
                <a href="javascript:void(0);" class="page _bg_bg_page_03">下页</a>
                <a href="javascript:void(0);" class="page _bg_bg_page_04">末页</a>
                <select class="sel_page">
                    <option>50</option>
                    <option>150</option>
                    <option>200</option>
                </select>
            </div>
        </div>
    </div>
</body>
